package com.swz.dcrm.adpter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.ClueRecord;
import com.swz.dcrm.model.DeliveryCar;
import com.swz.dcrm.util.DateUtils;

import java.util.List;

public class DeliveryCarAdapter extends CustomAdapter<DeliveryCar> {



    private Drawable drawableRed;
    private Drawable drawableOrg;
    private Drawable drawableBlue;
    private Drawable drawableGreen;
    private TodayPlanAdapter.OnButtonClick onButtonClick;
    public DeliveryCarAdapter(Context context, List<DeliveryCar> datas) {

        super(context, R.layout.item_today_plan, datas);

        drawableBlue=context.getResources().getDrawable(R.drawable.shape_circle_blue);
        drawableOrg=context.getResources().getDrawable(R.drawable.shape_circle_orange);
        drawableRed=context.getResources().getDrawable(R.drawable.shape_circle_red);
        drawableGreen=context.getResources().getDrawable(R.drawable.shape_circle_green);
    }

    @Override
    protected void convert(ViewHolder holder, DeliveryCar deliveryCar, int position) {
        ClueRecord clueRecord=deliveryCar.getClueRecord();
        holder.setText(R.id.tv_name,clueRecord.getBsClueVO().getCusName());
        holder.setText(R.id.tv_car_type,clueRecord.getBsClueVO().getIntentCar());
        holder.getView(R.id.btn_hand_up).setVisibility(View.GONE);
        if(clueRecord.getFollowType()!=0){
            holder.setText(R.id.tv_last_visit,mContext.getResources().getString(R.string.item_last_visit, DateUtils.dateFormat(clueRecord.getCreateTime(),"yyyy-MM-dd"),clueRecord.getFollowTypeDesc()));
        }else {
            holder.setText(R.id.tv_last_visit,mContext.getResources().getString(R.string.item_last_visit,"尚未填写",""));
        }
        if(clueRecord.getNextFollowTime()!=null){
            holder.setText(R.id.tv_next_visit,mContext.getResources().getString(R.string.item_next_visit,DateUtils.dateFormat(clueRecord.getNextFollowTime(),"yyyy-MM-dd"),
                    clueRecord.getNextFollowTypeDesc()));
        }else {
            holder.setText(R.id.tv_next_visit,mContext.getResources().getString(R.string.item_next_visit,"尚未填写",""));
        }
        if(clueRecord.getBsClueVO().getLevelDesc()!=null){
            holder.setText(R.id.tv_level,clueRecord.getBsClueVO().getLevelDesc().substring(0,1));
        }

        holder.setText(R.id.tv_sex,clueRecord.getBsClueVO().sexDesc());


        holder.setText(R.id.tv_fail_reason,mContext.getString(R.string.item_fail_reason,clueRecord.getBsClueVO().getDefeatedReason()));
        holder.setOnClickListener(R.id.btn_hand_up,v -> {

            if(onButtonClick!=null){
                onButtonClick.onHandUp(clueRecord.getBsClueVO().getId());
            }
        });
        holder.setOnClickListener(R.id.btn_logging,v -> {
            if(onButtonClick!=null){
                onButtonClick.onLogging(clueRecord);
            }
        });
        holder.setOnClickListener(R.id.btn_call,v -> {
            if(onButtonClick!=null){
                onButtonClick.onCall(clueRecord.getBsClueVO().getCusPhone());
            }
        });
        holder.itemView.setOnClickListener(v -> {
            setCurrentClickPosition(position);
            if(onClickListener!=null){
                onClickListener.onItemClick(deliveryCar);
            }
        });
    }

    public void setOnButtonClick(TodayPlanAdapter.OnButtonClick onButtonClick) {
        this.onButtonClick = onButtonClick;
    }
}
